//
//  NSString+ChangeFormat.m
//  Lfq
//
//  Created by 贺世昌 on 16/1/7.
//  Copyright © 2016年 文君. All rights reserved.
//

#import "NSString+ChangeFormat.h"
//#import "MyReachability.h"
#import <CoreText/CTStringAttributes.h>
#import <CoreLocation/CoreLocation.h>
#import <CommonCrypto/CommonDigest.h>
@implementation NSString (ChangeFormat)

//变换时间格式
+(NSString *)changeDateFormat:(NSString *)str{
    str = [self getNowDataStringForString:str];
    NSArray *dateArr = [str componentsSeparatedByString:@" "];
    NSString * dateStr = [dateArr firstObject];
    
    NSArray *arr = [dateStr componentsSeparatedByString:@"-"];
    NSString *date1 = [arr componentsJoinedByString:@"."];
    NSString *goodName = [NSString stringWithFormat:@"%@ %@",date1,[dateArr lastObject]];
    
    return goodName;
}
+ (NSString *)changeLiveDateyymmdd:(NSString *)string{
    //string = [self getNowDataStringForString:string];
    NSArray *dateArr = [string componentsSeparatedByString:@" "];
    NSString * dateStr = [dateArr firstObject];
    NSArray *arr = [dateStr componentsSeparatedByString:@"-"];
    NSMutableArray *mutabelArr = [NSMutableArray arrayWithCapacity:1];
    NSString *years = [NSString stringWithFormat:@"%@年",[arr firstObject]];
    [mutabelArr addObject:years];
    
    NSString *mouth = [NSString stringWithFormat:@"%@月",[arr objectAtIndex:1]];
    [mutabelArr addObject:mouth];
    
    
    NSString *day = [NSString stringWithFormat:@"%@日",[arr lastObject]];
    [mutabelArr addObject:day];
    
    NSString *str = [mutabelArr componentsJoinedByString:@""];
    return str;
    
}
+ (NSString *)changDateString:(NSString *)string{
    
    string = [self getNowDataStringForString:string];
    NSArray *dateArr = [string componentsSeparatedByString:@" "];
    NSString *str = [dateArr firstObject];
    NSArray *arr = [str componentsSeparatedByString:@"-"];
    NSString *newStr = [arr componentsJoinedByString:@"."];
    return newStr;
    
}
+ (NSComparisonResult )compareNowDateAndStartDate:(NSString *)stareDateStr AndDuration:(NSString *)duration{
    NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *startDate = [dateformatter dateFromString:stareDateStr];
    
    NSDate *startTime = [self getNowDateFromatAnDate:startDate];
    NSTimeInterval interval = 60*[duration integerValue];
    NSDate *endTime = [[NSDate date] initWithTimeInterval:interval sinceDate:startTime];
    NSDate *currentDate = [NSDate date];//获取当前时间，日期
    NSComparisonResult result =  [currentDate compare:endTime];
    return result;
}
+ (NSString *)getNowDataStringForString:(NSString *)time{
    
    NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *startDate = [dateformatter dateFromString:time];
    NSDate *startTime = [self getNowDateFromatAnDate:startDate];
    NSString *startDateStr = [dateformatter stringFromDate:startTime];
    return startDateStr;
    
}
+ (NSDate *)getNowDateFromatAnDate:(NSDate *)anyDate
{
    //设置源日期时区
    NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];//或GMT
    //设置转换后的目标日期时区
    NSTimeZone* destinationTimeZone = [NSTimeZone localTimeZone];
    //得到源日期与世界标准时间的偏移量
    NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:anyDate];
    //目标日期与本地时区的偏移量
    NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:anyDate];
    //得到时间偏移量的差值
    NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
    //转为现在时间
    NSDate* destinationDateNow = [[NSDate alloc] initWithTimeInterval:interval sinceDate:anyDate];
    return destinationDateNow;
}

+ (BOOL)stringContainsEmoji:(NSString *)string{
    __block BOOL returnValue = NO;
    
    [string enumerateSubstringsInRange:NSMakeRange(0, [string length])
                               options:NSStringEnumerationByComposedCharacterSequences
                            usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
                                const unichar hs = [substring characterAtIndex:0];
                                if (0xd800 <= hs && hs <= 0xdbff) {
                                    if (substring.length > 1) {
                                        const unichar ls = [substring characterAtIndex:1];
                                        const int uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
                                        if (0x1d000 <= uc && uc <= 0x1f77f) {
                                            returnValue = YES;
                                        }
                                    }
                                } else if (substring.length > 1) {
                                    const unichar ls = [substring characterAtIndex:1];
                                    if (ls == 0x20e3) {
                                        returnValue = YES;
                                    }
                                } else {
                                    if (0x2100 <= hs && hs <= 0x27ff) {
                                        returnValue = YES;
                                    } else if (0x2B05 <= hs && hs <= 0x2b07) {
                                        returnValue = YES;
                                    } else if (0x2934 <= hs && hs <= 0x2935) {
                                        returnValue = YES;
                                    } else if (0x3297 <= hs && hs <= 0x3299) {
                                        returnValue = YES;
                                    } else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030 || hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b || hs == 0x2b50) {
                                        returnValue = YES;
                                    }
                                }
                            }];
    
    return returnValue;
}

+ (NSString *)changeLiveDate:(NSString *)string{
    //string = [self getNowDataStringForString:string];
    NSArray *dateArr = [string componentsSeparatedByString:@" "];
    NSString * dateStr = [dateArr firstObject];
    NSString * timeStr = [dateArr lastObject];
    NSArray *arr = [dateStr componentsSeparatedByString:@"-"];
    NSMutableArray *mutabelArr = [NSMutableArray arrayWithCapacity:1];
    NSString *years = [NSString stringWithFormat:@"%@年",[arr firstObject]];
    [mutabelArr addObject:years];
    
    NSString *mouth = [NSString stringWithFormat:@"%@月",[arr objectAtIndex:1]];
    [mutabelArr addObject:mouth];
    
    
    NSString *day = [NSString stringWithFormat:@"%@日",[arr lastObject]];
    [mutabelArr addObject:day];
    
    [mutabelArr addObject:timeStr];
    
    NSString *str = [mutabelArr componentsJoinedByString:@"  "];
    return str;

}


+(NSString *)changeShowDate:(NSString *)str{
    NSString *time;
    NSInteger remainTime = [str integerValue];
    NSInteger day = remainTime/86400;
    NSInteger hour = (remainTime-day*86400)/3600;
    NSInteger minute = (remainTime-day*86400-hour*3600)/60;
    NSInteger second = (remainTime-day*86400-hour*3600-minute*60);
    NSString *hourTime = [self changeTimeNumber:hour];
    NSString *mimuteTime = [self changeTimeNumber:minute];
    NSString *secondTime = [self changeTimeNumber:second];
    if (day>0) {
        NSString *dayTime = [NSString stringWithFormat:@"%ld天",(long)day];
        time = [NSString stringWithFormat:@"还剩%@%@:%@:%@",dayTime, hourTime, mimuteTime, secondTime];
    }else if(hour>0){
        time = [NSString stringWithFormat:@"还剩%@:%@:%@", hourTime, mimuteTime, secondTime];
    }else {
        time = [NSString stringWithFormat:@"还剩%@:%@", mimuteTime, secondTime];
    }
    return time;
}
+ (NSString *)changeTimeNumber:(NSInteger)time{
    NSString *str = [NSString stringWithFormat:@"%.2ld",(long)time];
    return str;
}

+ (NSString *)changTime:(NSString *)string{
    NSInteger   time = [string integerValue];
    NSInteger static minit;
    NSInteger static second;
    minit = time / 60;
    second= time - 60 * minit;
    
    return [NSString stringWithFormat:@"%02ld'%02ld''", (long)minit, (long)second];
}
+ (NSString *)SecondChangMinuteTime:(NSString *)string{
    NSInteger   time = [string integerValue];
    NSInteger static minit;
    NSInteger static second;
    minit = time / 60;
    second= time % 60;
    
    return [NSString stringWithFormat:@"%02ld:%02ld", (long)minit, (long)second];
}
+ (BOOL)isValidateEmail:(NSString *)email
{
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES%@",emailRegex];
    return [emailTest evaluateWithObject:email];
}
#pragma mark - 判断是否是手机
+ (BOOL)isValidateMobile:(NSString *)mobile
{
    NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phoneTest evaluateWithObject:mobile];
}
+ (NSString *)changeShowNumber:(NSString *)numberStr{
    if ([numberStr integerValue] >0) {
        if ([numberStr integerValue]>999) {
            double number = (double)[numberStr integerValue]/1000.0;
            if (number >999.9) {
                numberStr = [NSString stringWithFormat:@"999.9k+"];
            }else{
                numberStr = [NSString stringWithFormat:@"%.1lfk",number];
            }
        }
    }
    return numberStr;

}
+ (BOOL)validateMobile:(NSString *)mobileNum

{
    
    /**
     
     * 手机号码
     
     * 移动：134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
     
     * 联通：130,131,132,152,155,156,185,186
     
     * 电信：133,1349,153,180,189
     
     */
    
    NSString * MOBILE = @"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";
    
    /**
     
     10         * 中国移动：China Mobile
     
     11         * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
     
     12         */
    
    NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";
    
    /**
     
     15         * 中国联通：China Unicom
     
     16         * 130,131,132,152,155,156,185,186
     
     17         */
    
    NSString * CU = @"^1(3[0-2]|5[256]|7[01678]|8[56])\\d{8}$";
    
    /**
     
     20         * 中国电信：China Telecom
     
     21         * 133,1349,153,180,189
     
     22         */
    
    NSString *CT =@"^1((33|53|8[09])[0-9]|349)\\d{7}$";
    
    /**
     
     25         * 大陆地区固话及小灵通
     
     26         * 区号：010,020,021,022,023,024,025,027,028,029
     
     27         * 号码：七位或八位
     
     28         */
    
    NSString *PHS = @"\\d{3}-\\d{7,8}|\\d{4}-\\d{7,8}";
   
    NSString *aaa = @"^\\s*\\+?\\s*(\\(\\s*\\d+\\s*\\)|\\d+)(\\s*-?\\s*(\\(\\s*\\d+\\s*\\)|\\s*\\d+\\s*))*\\s*$";
    
    
    
    
    NSString *newPh = @"^1[3|4|5|7|8][0-9]{9}$";
    NSPredicate *regextestNew = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", newPh];
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    
    NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",CM];
    
    NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",CU];
    
    NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",CT];
    NSPredicate *regextestPHS = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",PHS];
   NSPredicate *regextestAA = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", aaa];
    
    if(([regextestmobile evaluateWithObject:mobileNum] == YES)
       
       || ([regextestcm evaluateWithObject:mobileNum] == YES)
       
       || ([regextestct evaluateWithObject:mobileNum] == YES)
       
       || ([regextestcu evaluateWithObject:mobileNum] == YES)
       || ([regextestPHS evaluateWithObject:mobileNum] == YES)
       ||([regextestNew evaluateWithObject:mobileNum] == YES)||([regextestAA evaluateWithObject:mobileNum]))
        
    {
        
        return YES;
        
    }
    
    else
        
    {
        
        return NO;
        
    }
    
}
+ (NSString *)getNearByShow:(NSString *)str{
    NSInteger number = [str integerValue];
    if (number >999) {
        str = @"999+";
    }
    return str;

}

+ (NSString *)GetClassTagForNSString:(NSString *)str{
    NSString *tag;
    str = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
    str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    if ([str isEqualToString:@"尴尬日报"]) {
        tag = @"S0184";
    }else if ([str isEqualToString:@"望闻诊切"]) {
        tag = @"S0185";
    }else if ([str isEqualToString:@"哈哈幽默"]) {
        tag = @"S0186";
    }else if ([str isEqualToString:@"艺术大家"]) {
        tag = @"S0187";
    }else if ([str isEqualToString:@"主播绝活"]) {
        tag = @"S0188";
    }else if ([str isEqualToString:@"活动招募"]) {
        tag = @"S0189";
    }else if ([str isEqualToString:@"派对招募"]) {
        tag = @"S0190";
    }else if ([str isEqualToString:@"结伴旅行"]) {
        tag = @"S0191";
    }else if ([str isEqualToString:@"生活窍门"]) {
        tag = @"S0192";
    }else if ([str isEqualToString:@"意想不到"]) {
        tag = @"S0193";
    }else if ([str isEqualToString:@"看家本领"]) {
        tag = @"S0194";
    }else if ([str isEqualToString:@"江湖秘籍"]) {
        tag = @"S0195";
    }else if ([str isEqualToString:@"玩转职场"]) {
        tag = @"S0196";
    }else if ([str isEqualToString:@"创意无限"]) {
        tag = @"S0197";
    }else if ([str isEqualToString:@"英语专场"]) {
        tag = @"S0198";
    }else if ([str isEqualToString:@"歪果仁授课"]) {
        tag = @"S0199";
    }else if ([str isEqualToString:@"八分钟课堂"]) {
        tag = @"S0200";
    }else if ([str isEqualToString:@"恶补数理化"]) {
        tag = @"S0201";
    }else if ([str isEqualToString:@"超级编程"]) {
        tag = @"S0202";
    }else if ([str isEqualToString:@"科幻狂想"]) {
        tag = @"S0203";
    }else if ([str isEqualToString:@"海内外法律"]) {
        tag = @"S0204";
    }else if ([str isEqualToString:@"智商小课堂"]) {
        tag = @"S0205";
    }else if ([str isEqualToString:@"高考小秘籍"]) {
        tag = @"S0206";
    }else if ([str isEqualToString:@"获奖作品"]) {
        tag = @"S0207";
    }else if ([str isEqualToString:@"口述小说"]) {
        tag = @"S0208";
    }else if ([str isEqualToString:@"最美文学"]) {
        tag = @"S0209";
    }else if ([str isEqualToString:@"脱口而出"]) {
        tag = @"S0210";
    }else if ([str isEqualToString:@"海阔天空"]) {
        tag = @"S0211";
    }else if ([str isEqualToString:@"情商升级"]) {
        tag = @"S0212";
    }else if ([str isEqualToString:@"我是名人"]) {
        tag = @"S0213";
    }else if ([str isEqualToString:@"电影扯谈"]) {
        tag = @"S0214";
    }else if ([str isEqualToString:@"有问必答"]) {
        tag = @"S0215";
    }else if ([str isEqualToString:@"静思养神"]) {
        tag = @"S0216";
    }else if ([str isEqualToString:@"文化苦旅"]) {
        tag = @"S0217";
    }else if ([str isEqualToString:@"语言专家"]) {
        tag = @"S0218";
    }else if ([str isEqualToString:@"发明创意"]) {
        tag = @"S0219";
    }else if ([str isEqualToString:@"科幻大咖"]) {
        tag = @"S0220";
    }else if ([str isEqualToString:@"游戏狂人"]) {
        tag = @"S0221";
    }else if ([str isEqualToString:@"为你读诗"]) {
        tag = @"S0222";
    }else if ([str isEqualToString:@"读读好书"]) {
        tag = @"S0223";
    }else if ([str isEqualToString:@"游遍世界"]) {
        tag = @"S0224";
    }else if ([str isEqualToString:@"吃遍全球"]) {
        tag = @"S0225";
    }else if ([str isEqualToString:@"CEO专场"]) {
        tag = @"S0226";
    }else if ([str isEqualToString:@"保险专场"]) {
        tag = @"S0227";
    }else if ([str isEqualToString:@"投资人专场"]) {
        tag = @"S0228";
    }else if ([str isEqualToString:@"留学专场"]) {
        tag = @"S0229";
    }else if ([str isEqualToString:@"明星专场"]) {
        tag = @"S0230";
    }else if ([str isEqualToString:@"瘦身专场"]) {
        tag = @"S0231";
    }else if ([str isEqualToString:@"学霸专场"]) {
        tag = @"S0232";
    }else if ([str isEqualToString:@"国考专场"]) {
        tag = @"S0233";
    }else if ([str isEqualToString:@"挂科辅导"]) {
        tag = @"S0234";
    }else if ([str isEqualToString:@"首席设计师"]) {
        tag = @"S0235";
    }else if ([str isEqualToString:@"原创设计"]) {
        tag = @"S0236";
    }else if ([str isEqualToString:@"总监谈品牌"]) {
        tag = @"S0237";
    }else if ([str isEqualToString:@"品牌创始人"]) {
        tag = @"S0238";
    }else if ([str isEqualToString:@"品牌文化"]) {
        tag = @"S0239";
    }else if ([str isEqualToString:@"亲民奢侈品"]) {
        tag = @"S0240";
    }else if ([str isEqualToString:@"顶尖美食"]) {
        tag = @"S0241";
    }else if ([str isEqualToString:@"珍品零食"]) {
        tag = @"S0242";
    }else if ([str isEqualToString:@"品牌工作室"]) {
        tag = @"S0243";
    }else if ([str isEqualToString:@"品牌现场"]) {
        tag = @"S0244";
    }else if ([str isEqualToString:@"品牌折扣中"]) {
        tag = @"S0245";
    }else if ([str isEqualToString:@"品牌双十一"]) {
        tag = @"S0246";
    }else if ([str isEqualToString:@"品牌节日惠"]) {
        tag = @"S0247";
    }else if ([str isEqualToString:@"新款发布"]) {
        tag = @"S0248";
    }else if ([str isEqualToString:@"瘦身名品"]) {
        tag = @"S0249";
    }else if ([str isEqualToString:@"婴童名品"]) {
        tag = @"S0250";
    }else if ([str isEqualToString:@"模特试穿"]) {
        tag = @"S0251";
    }else if ([str isEqualToString:@"明星试穿"]) {
        tag = @"S0252";
    }else if ([str isEqualToString:@"主播试穿"]) {
        tag = @"S0253";
    }else if ([str isEqualToString:@"设计师谈潮流"]) {
        tag = @"S0254";
    }else if ([str isEqualToString:@"着装不纠结"]) {
        tag = @"S0255";
    }else if ([str isEqualToString:@"私家定制"]) {
        tag = @"S0256";
    }else if ([str isEqualToString:@"品牌定制"]) {
        tag = @"S0257";
    }else if ([str isEqualToString:@"品牌公益"]) {
        tag = @"S0258";
    }else if ([str isEqualToString:@"名车驾到"]) {
        tag = @"S0259";
    }else if ([str isEqualToString:@"亭亭试衣间"]) {
        tag = @"S0260";
    }else if ([str isEqualToString:@"美裙美妆"]) {
        tag = @"S0261";
    }else if ([str isEqualToString:@"日韩范儿"]) {
        tag = @"S0262";
    }else if ([str isEqualToString:@"欧洲时尚"]) {
        tag = @"S0263";
    }else if ([str isEqualToString:@"文艺青年"]) {
        tag = @"S0264";
    }else if ([str isEqualToString:@"复古潮"]) {
        tag = @"S0265";
    }else if ([str isEqualToString:@"潮流不跟风"]) {
        tag = @"S0266";
    }else if ([str isEqualToString:@"明星爆款"]) {
        tag = @"S0267";
    }else if ([str isEqualToString:@"智能科技"]) {
        tag = @"S0268";
    }else if ([str isEqualToString:@"极品改装件"]) {
        tag = @"S0269";
    }else if ([str isEqualToString:@"购车行家帮"]) {
        tag = @"S0270";
    }else if ([str isEqualToString:@"旅游装备"]) {
        tag = @"S0271";
    }else if ([str isEqualToString:@"品牌内衣"]) {
        tag = @"S0272";
    }else if ([str isEqualToString:@"品牌比基尼"]) {
        tag = @"S0273";
    }else if ([str isEqualToString:@"国内旅游"]) {
        tag = @"S0275";
    }else if ([str isEqualToString:@"国内代购"]) {
        tag = @"S0276";
    }else if ([str isEqualToString:@"海外旅游"]) {
        tag = @"S0277";
    }else if ([str isEqualToString:@"海外品牌"]) {
        tag = @"S0278";
    }else if ([str isEqualToString:@"海外代购"]) {
        tag = @"S0279";
    }else if ([str isEqualToString:@"VIP课程"]) {
        tag = @"S0280";
    }else if ([str isEqualToString:@"私家一对一"]) {
        tag = @"S0281";
    }else if ([str isEqualToString:@"名家教室"]) {
        tag = @"S0282";
    }else if ([str isEqualToString:@"欧洲潮流"]) {
        tag = @"S0283";
    }else if ([str isEqualToString:@"国萃文化"]) {
        tag = @"S0284";
    }else if ([str isEqualToString:@"亚洲潮流"]) {
        tag = @"S0285";
    }else if ([str isEqualToString:@"顶级买手"]) {
        tag = @"S0286";
    }else if ([str isEqualToString:@"华人教学"]) {
        tag = @"S0287";
    }else if ([str isEqualToString:@"教授专场"]) {
        tag = @"S0288";
    }else if ([str isEqualToString:@"房产投资"]) {
        tag = @"S0289";
    }else if ([str isEqualToString:@"旅游专线"]) {
        tag = @"S0290";
    }else if ([str isEqualToString:@"情绪大学"]) {
        tag = @"S0291";
    }else if ([str isEqualToString:@"时间管理"]) {
        tag = @"S0292";
    }else if ([str isEqualToString:@"抑郁拆解"]) {
        tag = @"S0293";
    }else if ([str isEqualToString:@"新片上映"]) {
        tag = @"S0294";
    }else if ([str isEqualToString:@"明星代言"]) {
        tag = @"S0295";
    }else if ([str isEqualToString:@"星座专场"]) {
        tag = @"S0296";
    }else if ([str isEqualToString:@"股票投资"]) {
        tag = @"S0297";
    }else if ([str isEqualToString:@"女生私密"]) {
        tag = @"S0298";
    }else if ([str isEqualToString:@"男生私密"]) {
        tag = @"S0299";
    }else if ([str isEqualToString:@"古典音乐"]) {
        tag = @"S0300";
    }else if ([str isEqualToString:@"流行音乐"]) {
        tag = @"S0301";
    }else if ([str isEqualToString:@"纯粹艺术"]) {
        tag = @"S0302";
    }else if ([str isEqualToString:@"超级App"]) {
        tag = @"S0303";
    }else if ([str isEqualToString:@"每天黑科技"]) {
        tag = @"S0304";
    }else if ([str isEqualToString:@"大牛技术专场"]) {
        tag = @"S0305";
    }else if ([str isEqualToString:@"顶尖买手"]) {
        tag = @"S0306";
    }else if ([str isEqualToString:@"亚洲时尚"]) {
        tag = @"S0307";
    }else if ([str isEqualToString:@"超级应用"]) {
        tag = @"S0308";
    }else if ([str isEqualToString:@"艺术品鉴"]) {
        tag = @"S0309";
    }else if ([str isEqualToString:@"科技爆品"]) {
        tag = @"S0310";
    }else if ([str isEqualToString:@"超级设计"]) {
        tag = @"S0311";
    }else if ([str isEqualToString:@"创意无底线"]) {
        tag = @"S0312";
    }else if ([str isEqualToString:@"男士必备"]) {
        tag = @"S0313";
    }else if ([str isEqualToString:@"女士必备"]) {
        tag = @"S0314";
    }else if ([str isEqualToString:@"主播瘦身中"]) {
        tag = @"S0315";
    }
    return tag;



}
+ (NSString *)GetTagForNSString:(NSString *)str{
    NSString *tag;
    str = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
    str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    if ([str isEqualToString:@"全球酒店"]) {
        tag = @"S0011";
    }else if ([str isEqualToString:@"VR/AR"]) {
        tag = @"S0012";
    }else if ([str isEqualToString:@"主播体验"]) {
        tag = @"S0013";
    }else if ([str isEqualToString:@"主播剁手价"]) {
        tag = @"S0014";
    }else if ([str isEqualToString:@"主播双十一"]) {
        tag = @"S0015";
    }else if ([str isEqualToString:@"主播密报"]) {
        tag = @"S0016";
    }else if ([str isEqualToString:@"纯粹艺术"]) {
        tag = @"S0021";
    }else if ([str isEqualToString:@"首席设计师"]) {
        tag = @"S0022";
    }else if ([str isEqualToString:@"主播旅行"]) {
        tag = @"S0023";
    }else if ([str isEqualToString:@"主播日报"]) {
        tag = @"S0024";
    }else if ([str isEqualToString:@"主播授课"]) {
        tag = @"S0025";
    }else if ([str isEqualToString:@"主播私密价"]) {
        tag = @"S0026";
    }else if ([str isEqualToString:@"主播节日惠"]) {
        tag = @"S0031";
    }else if ([str isEqualToString:@"主播瘦身中"]) {
        tag = @"S0032";
    }else if ([str isEqualToString:@"主播试吃"]) {
        tag = @"S0033";
    }else if ([str isEqualToString:@"主播试穿"]) {
        tag = @"S0034";
    }else if ([str isEqualToString:@"五星民宿"]) {
        tag = @"S0035";
    }else if ([str isEqualToString:@"亭亭玉立化妆间"]) {
        tag = @"S0036";
    }else if ([str isEqualToString:@"亭亭玉立时装周"]) {
        tag = @"S0041";
    }else if ([str isEqualToString:@"亭亭玉立试衣间"]) {
        tag = @"S0042";
    }else if ([str isEqualToString:@"内衣控"]) {
        tag = @"S0043";
    }else if ([str isEqualToString:@"化妆名品"]) {
        tag = @"S0045";
    }else if ([str isEqualToString:@"古典音乐会"]) {
        tag = @"S0046";
    }else if ([str isEqualToString:@"主播绝活"]) {
        tag = @"S0051";
    }else if ([str isEqualToString:@"名厨夜宴"]) {
        tag = @"S0052";
    }else if ([str isEqualToString:@"名车驾到"]) {
        tag = @"S0053";
    }else if ([str isEqualToString:@"品牌发布会"]) {
        tag = @"S0054";
    }else if ([str isEqualToString:@"品牌创意"]) {
        tag = @"S0055";
    }else if ([str isEqualToString:@"品牌现场"]) {
        tag = @"S0056";
    }else if ([str isEqualToString:@"奢侈生活"]) {
        tag = @"S0061";
    }else if ([str isEqualToString:@"女人装"]) {
        tag = @"S0062";
    }else if ([str isEqualToString:@"微公益"]) {
        tag = @"S0063";
    }else if ([str isEqualToString:@"微喜剧"]) {
        tag = @"S0064";
    }else if ([str isEqualToString:@"微幽默"]) {
        tag = @"S0065";
    }else if ([str isEqualToString:@"微恶搞"]) {
        tag = @"S0066";
    }else if ([str isEqualToString:@"3D动画"]) {
        tag = @"S0071";
    }else if ([str isEqualToString:@"微电影"]) {
        tag = @"S0072";
    }else if ([str isEqualToString:@"微话剧"]) {
        tag = @"S0073";
    }else if ([str isEqualToString:@"微音乐"]) {
        tag = @"S0074";
    }else if ([str isEqualToString:@"数码控"]) {
        tag = @"S0075";
    }else if ([str isEqualToString:@"品牌历史"]) {
        tag = @"S0076";
    }else if ([str isEqualToString:@"比基尼"]) {
        tag = @"S0081";
    }else if ([str isEqualToString:@"流行音乐会"]) {
        tag = @"S0082";
    }else if ([str isEqualToString:@"爱帽子"]) {
        tag = @"S0083";
    }else if ([str isEqualToString:@"爱眼镜"]) {
        tag = @"S0084";
    }else if ([str isEqualToString:@"爱香水"]) {
        tag = @"S0085";
    }else if ([str isEqualToString:@"珍品美食"]) {
        tag = @"S0086";
    }else if ([str isEqualToString:@"男人装"]) {
        tag = @"S0091";
    }else if ([str isEqualToString:@"舞蹈"]) {
        tag = @"S0092";
    }else if ([str isEqualToString:@"私家定制"]) {
        tag = @"S0093";
    }else if ([str isEqualToString:@"美包包"]) {
        tag = @"S0094";
    }else if ([str isEqualToString:@"美裙美幻"]) {
        tag = @"S0095";
    }else if ([str isEqualToString:@"美鞋界"]) {
        tag = @"S0096";
    }else if ([str isEqualToString:@"主播代言"]) {
        tag = @"S0101";
    }else if ([str isEqualToString:@"顶级珠宝"]) {
        tag = @"S0102";
    }else if ([str isEqualToString:@"VR/AR装备"]) {
        tag = @"S0103";
    }else if ([str isEqualToString:@"中餐"]) {
        tag = @"S0104";
    }else if ([str isEqualToString:@"内衣"]) {
        tag = @"S0105";
    }else if ([str isEqualToString:@"创客智能"]) {
        tag = @"S0106";
    }else if ([str isEqualToString:@"包包"]) {
        tag = @"S0111";
    }else if ([str isEqualToString:@"化妆"]) {
        tag = @"S0112";
    }else if ([str isEqualToString:@"奢侈用品"]) {
        tag = @"S0113";
    }else if ([str isEqualToString:@"女必备"]) {
        tag = @"S0114";
    }else if ([str isEqualToString:@"女装"]) {
        tag = @"S0115";
    }else if ([str isEqualToString:@"婴童名品"]) {
        tag = @"S0116";
    }else if ([str isEqualToString:@"帽子"]) {
        tag = @"S0121";
    }else if ([str isEqualToString:@"数码"]) {
        tag = @"S0122";
    }else if ([str isEqualToString:@"比基尼"]) {
        tag = @"S0124";
    }else if ([str isEqualToString:@"汽车"]) {
        tag = @"S0126";
    }else if ([str isEqualToString:@"潮人装"]) {
        tag = @"S0131";
    }else if ([str isEqualToString:@"珠宝首饰"]) {
        tag = @"S0132";
    }else if ([str isEqualToString:@"男必备"]) {
        tag = @"S0133";
    }else if ([str isEqualToString:@"男装"]) {
        tag = @"S0134";
    }else if ([str isEqualToString:@"男鞋"]) {
        tag = @"S0135";
    }else if ([str isEqualToString:@"眼镜"]) {
        tag = @"S0136";
    }else if ([str isEqualToString:@"礼品"]) {
        tag = @"S0141";
    }else if ([str isEqualToString:@"私家客机"]) {
        tag = @"S0142";
    }else if ([str isEqualToString:@"美裙"]) {
        tag = @"S0143";
    }else if ([str isEqualToString:@"美鞋"]) {
        tag = @"S0144";
    }else if ([str isEqualToString:@"美食"]) {
        tag = @"S0145";
    }else if ([str isEqualToString:@"老字号"]) {
        tag = @"S0146";
    }else if ([str isEqualToString:@"西餐"]) {
        tag = @"S0151";
    }else if ([str isEqualToString:@"零食"]) {
        tag = @"S0153";
    }else if ([str isEqualToString:@"香水"]) {
        tag = @"S0154";
    }else if ([str isEqualToString:@"跨境电商"]) {
        tag = @"S0155";
    }else if ([str isEqualToString:@"授权代理"]) {
        tag = @"S0156";
    }else if ([str isEqualToString:@"本地代购"]) {
        tag = @"S0161";
    }else if ([str isEqualToString:@"海外代购"]) {
        tag = @"S0162";
    }else if ([str isEqualToString:@"私人原创"]) {
        tag = @"S0163";
    }else if ([str isEqualToString:@"自创品牌"]) {
        tag = @"S0164";
    }else if ([str isEqualToString:@"自贸直营"]) {
        tag = @"S0165";
    }else if ([str isEqualToString:@"传统模式"]) {
        tag = @"S0166";
    }else if ([str isEqualToString:@"私密价"]) {
        tag = @"S0171";
    }else if ([str isEqualToString:@"递减"]) {
        tag = @"S0172";
    }else if ([str isEqualToString:@"递减随机"]) {
        tag = @"S0173";
    }else if ([str isEqualToString:@"递增"]) {
        tag = @"S0174";
    }else if ([str isEqualToString:@"递增随机"]) {
        tag = @"S0175";
    }else if ([str isEqualToString:@"随机配价"]) {
        tag = @"S0176";
    }else if ([str isEqualToString:@"优质生活"]) {
        tag = @"S0177";
    }else if ([str isEqualToString:@"超级应用"]) {
        tag = @"S0178";
    }else if ([str isEqualToString:@"新片上映"]) {
        tag = @"S0179";
    }else if ([str isEqualToString:@"乐趣旅行"]) {
        tag = @"S0180";
    }else if ([str isEqualToString:@"房产投资"]) {
        tag = @"S0181";
    }else if ([str isEqualToString:@"科幻"]) {
        tag = @"S0182";
    }
    
    
    return tag;
    
}
+ (NSString *)getNewLiveTagFor:(NSString *)str{
    NSString *tag;
    str = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
    str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    if ([str isEqualToString:@"原创设计"]) {
        tag = @"S0236";
    }else if ([str isEqualToString:@"音乐"]){
        tag = @"S0025016";
    }else if ([str isEqualToString:@"主播授课"]){
        tag = @"S0025";
    }else if ([str isEqualToString:@"游遍世界"]){
        tag = @"S0224";
    }else if ([str isEqualToString:@"纯粹艺术"]){
        tag = @"S0302";
    }else if ([str isEqualToString:@"最美文学"]){
        tag = @"S0209";
    }else if ([str isEqualToString:@"品牌文化"]){
        tag = @"S0239";
    }else if ([str isEqualToString:@"超级APP"]){
        tag = @"S0303";
    }else if ([str isEqualToString:@"哈哈幽默"]){
        tag = @"S0186";
    }else if ([str isEqualToString:@"吃遍全球"]){
        tag = @"S0225";
    }else if ([str isEqualToString:@"每日黑科技"]){
        tag = @"S0316";
    }else if ([str isEqualToString:@"品牌代言"]){
        tag = @"S0317";
    }else if ([str isEqualToString:@"品牌折扣中"]){
        tag = @"S0318";
    }else if ([str isEqualToString:@"轻奢主义"]){
        tag = @"S0319";
    }else if ([str isEqualToString:@"投资频道"]){
        tag = @"S0320";
    }else if ([str isEqualToString:@"望闻诊切"]){
        tag = @"S0321";
    }else if ([str isEqualToString:@"最美职业"]){
        tag = @"S0322";
    }else if ([str isEqualToString:@"你好先生"]){
        tag = @"S0323";
    }else if ([str isEqualToString:@"你好姑娘"]){
        tag = @"S0324";
    }
    return tag;
}
+ (NSString *)getIconImageSize:(NSString *)path{

    path = [NSString stringWithFormat:@"%@?x-oss-process=image/resize,w_150,limit_0",path];
    return path;
}
+ (NSString *)getDistanceShow:(NSString *)str{
    double distance = [str doubleValue];
    NSString *showStr;
    if (distance >1000) {
        showStr = [NSString stringWithFormat:@"%.2lf 公里",distance/1000];
        
    }else{
        if (distance<0) {
           showStr = @"一光年";
        }else{
            showStr = [NSString stringWithFormat:@"%ld 米",(long)[str integerValue]];
        }
        
    }

    return showStr;
}

#pragma mark设置取出cookie
+ (NSString *)getcookieInfo:(NSString *)url{
    NSArray * cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:url]];
    for (NSHTTPCookie * cookie in cookies){
        NSArray *headCookie = [NSHTTPCookie cookiesWithResponseHeaderFields:[NSDictionary dictionaryWithObject:[[NSString alloc]initWithFormat:@"%@=%@",[cookie name],[cookie value]] forKey:@"set-cookie"] forURL:[NSURL URLWithString:url]];
        [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies:headCookie forURL:[NSURL URLWithString:url] mainDocumentURL:nil];
    }
    return url;
}
+(NSString *)MD5Sring:(NSString *)str{
    const char * cStr  = [str UTF8String];
    unsigned char result[32];
    //    unsigned char result[CC_MD5_DIGEST_LENGTH];
    //    CC_MD5(cStr, strlen(cStr), result);
    CC_MD5(cStr, (CC_LONG)strlen(cStr),result);
    NSMutableString * result1 = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
        [result1 appendFormat:@"%02x", result[i]];
    return result1;
}
+ (NSMutableAttributedString *)getArributedStringForString:(NSString *)str andCharacterSpacing:(short)number{
    NSMutableAttributedString * attributedString =[[NSMutableAttributedString alloc]initWithString:str];
    //设置字间距
    
    CFNumberRef num = CFNumberCreate(kCFAllocatorDefault,kCFNumberSInt8Type,&number);
    [attributedString addAttribute:(id)kCTKernAttributeName value:(__bridge id)num range:NSMakeRange(0,[attributedString length])];
    CFRelease(num);
    return attributedString;




}
+ (CGFloat)getHeightWithContent:(NSString *)content width:(CGFloat)width font:(CGFloat)font{
    
    CGRect rect = [content boundingRectWithSize:CGSizeMake(width, 999)
                                        options:NSStringDrawingUsesLineFragmentOrigin
                                     attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]}
                                        context:nil];
    return rect.size.height;
}
+ (NSString *)changePhoneStr:(NSString *)str{
    if (str.length <7) {
        return str;
    }
    NSString *phoneNumber = [str stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@"****"];
    return phoneNumber;

}
+ (NSString *)changeIdCardNumber:(NSString *)str{
    if (str.length < 14) {
        return str;
    }
    NSString *IdCardNumber = [str stringByReplacingCharactersInRange:NSMakeRange(0, 14) withString:@"**************"];
    return IdCardNumber;
}

+ (NSString *)getDistanceForOneLocationLatitude:(double)latitudeOne andOneLongitude:(double)longitudeOne{
    
    NSUserDefaults * defaults  = [NSUserDefaults standardUserDefaults];
    if ([defaults valueForKey:@"userLatitude"]) {
        double  latitudeTow = [[defaults valueForKey:@"userLatitude"] doubleValue];
        double longitudeTow = [[defaults valueForKey:@"userLongitude"] doubleValue];
        CLLocation *oneLocation = [[CLLocation alloc] initWithLatitude:latitudeOne longitude:longitudeOne];
        CLLocation *towLoacation =[[CLLocation alloc] initWithLatitude:latitudeTow longitude:longitudeTow];
        
        CLLocationDistance kilometers=[oneLocation distanceFromLocation:towLoacation];
        NSString *distance = [NSString stringWithFormat:@"%lf",kilometers];
        
        return [self getDistanceShow:distance];
    }else{
    
        return @"一光年";
    }
    
    


}

//
+ (NSString *)changeSendDateFormat:(NSString *)sendData{
    NSDate *date = [NSDate new];
    //服务器返回的时间
    NSDateFormatter *dateFormatter = [NSDateFormatter new];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *datefor = [dateFormatter dateFromString:sendData];
    
    //当前时间和服务器返回的时间的间隔
    NSTimeInterval interval = [date timeIntervalSinceDate:datefor];
    
    //然后转换为一秒为单位去计算

    
    if (interval < 24*3600){
        if (interval <1) {
            return @"1秒前";
        }else if (interval <60) {
            NSInteger second = (NSInteger)interval/1;
            return [NSString stringWithFormat:@"%ld秒前",(long)second];
            //            NSRange range = NSMakeRange (10, 6);
            //            return [sendData substringWithRange:range];
        }else if(interval <3600){
            NSInteger second = interval/60;
            return [NSString stringWithFormat:@"%ld分钟前",(long)second];
        }else{
            NSInteger second = interval/3600;
            return [NSString stringWithFormat:@"%ld小时前",(long)second];
        }
        
        
    }else if (interval< 48*3600){
        return @"昨天";
        
    }else if (interval < 72*3600){
        return @"前天";
        
    }else if(interval < 24*7*3600){
        return @"3天前";
        
    }else{
        return @"7天前";
    }
}


+ (BOOL) isBlankString:(NSString *)string {
    if (string == nil || string == NULL) {
        return YES;
    }
    if ([string isKindOfClass:[NSNull class]]) {
        return YES;
    }
    if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {
        return YES;
    }
    return NO;
}


+ (NSString*)GetPathByFileName:(NSString *)_fileName ofType:(NSString *)_type{
    NSString *directory = NSTemporaryDirectory();
    NSString* fileDirectory = [[[directory stringByAppendingPathComponent:_fileName]
                                stringByAppendingPathExtension:_type]
                               stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    return fileDirectory;
}
+ (NSString*)GetCurrentTimeString{
    NSDateFormatter *dateformat = [[NSDateFormatter  alloc]init];
    [dateformat setDateFormat:@"yyyyMMddHHmmss"];
    return [dateformat stringFromDate:[NSDate date]];
}


//获取当地时间 xxxx年xx月
+ (NSString *)getCurrentTime_HN {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy年MM月"];
    NSString *dateTime = [formatter stringFromDate:[NSDate date]];
    return dateTime;
}



//获取当地时间 xxxx年xx月xx日 获取年月日格式2017-11-1
+ (NSString *)yearMonthDay{
    
    NSDate  *currentDate = [NSDate date];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:currentDate];
    
    NSInteger year=[components year];
    NSInteger month=[components month];
    NSInteger day=[components day];
    NSLog(@"currentDate = %@ ,year = %ld ,month=%ld, day=%ld",currentDate,year,month,day);
    
    NSString *mm = [NSString stringWithFormat:@"%ld-%ld-%ld",year,month,day];
    
    
    return mm;
    
}


//获取年月日格式2017-11-01
+ (NSString *)currentDateTow{
    
    
    NSDate *date =[NSDate date];//简书 FlyElephant
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    
    [formatter setDateFormat:@"yyyy"];
    NSInteger currentYear=[[formatter stringFromDate:date] integerValue];
    [formatter setDateFormat:@"MM"];
    NSInteger currentMonth=[[formatter stringFromDate:date]integerValue];
    [formatter setDateFormat:@"dd"];
    NSInteger currentDay=[[formatter stringFromDate:date] integerValue];
    
    
    NSString *year = [NSString stringWithFormat:@"%ld", currentYear];
    NSString *mon = currentMonth < 10 ? [NSString stringWithFormat:@"0%ld", currentMonth] : [NSString stringWithFormat:@"%ld", currentMonth];
    NSString *day = currentDay < 10 ? [NSString stringWithFormat:@"0%ld", currentDay] : [NSString stringWithFormat:@"%ld", currentDay];
    
    
    return [NSString stringWithFormat:@"%@-%@-%@", year, mon, day];
}



/*
 获取每个月份的第一天  格式2017-10-01
 **/
+(NSString *)getCurrentDateYearMD{
    
    
    NSDate *date =[NSDate date];//简书 FlyElephant
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    
    [formatter setDateFormat:@"yyyy"];
    NSInteger currentYear=[[formatter stringFromDate:date] integerValue];
    [formatter setDateFormat:@"MM"];
    NSInteger currentMonth=[[formatter stringFromDate:date]integerValue];
    [formatter setDateFormat:@"dd"];
        NSInteger currentDay=[[formatter stringFromDate:date] integerValue];
    
    
    NSString *year = [NSString stringWithFormat:@"%ld", currentYear];
    NSString *mon = currentMonth < 10 ? [NSString stringWithFormat:@"0%ld", currentMonth] : [NSString stringWithFormat:@"%ld", currentMonth];
//    NSString *day = currentDay < 10 ? [NSString stringWithFormat:@"0%ld", currentDay] : [NSString stringWithFormat:@"%ld", currentDay];
    
    
    return [NSString stringWithFormat:@"%@-%@-01", year, mon];
}

+ (NSString *)hour{
    
    NSDate * date = [NSDate date];
    NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSTimeInterval time = 2 * 60 * 60;//秒数
    NSDate * hours = [date dateByAddingTimeInterval:-time];
    //转化为字符串
    NSString * startDate = [dateFormatter stringFromDate:hours];
    
    
    return startDate;
    
}


@end
